home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: newsfeed.internetmci.com!miwok!linex1!news
- From: mfried@linex.com (Marty Fried)
- Subject: Re: Help: Bitwise operators
- X-Nntp-Posting-Host: sp11.linex.com
- Message-ID: <31730b9a.4996728@news.linex.com>
- Sender: news@linex1.linex.com
- Organization: Cirrius Cybernetics Corp
- X-Newsreader: Forte Agent .99e/32.209
- References: <4knb73$f15@wumpus.its.uow.edu.au>
- Date: Tue, 16 Apr 1996 02:57:33 GMT
-
- Once upon a time (OK, it was 13 Apr 1996 14:40:03 +1000),
- sjl01@wumpus.its.uow.edu.au (Stuart John Langley) wrote:
-
- >Hi All,
- >
- >I need some help understanding some code that i need to translate.
- >I have the following,
- >
- >unsigned char byte;
- >
- >then either -
- >
- >byte = (byte >> 1) | 0;
- >
- >or
- >
- >byte = (byte >> 1) | 128;
- >
- >I know that the first case places a 0 in the left most bit of byte,
- >and moves everything else to the right, while the second places a 1
- >in the leftmost bit. However, when I look at the texts and hepfiles,
- >this seems to indicate thet the 0 or 1 should be placed in the rightmost
- >bit and everything else moved left. Can somebody please help me out with
- >this problem>
-
- Are you sure you know what the first one does? It seems to me that
- all it does is shift right one (or divides by 2, depending on how you
- look at it). ORing with zero has no effect. ANDing with zero would
- force the least significant byte to be zero (right most bit).
-
- ORing with 128 will force bit 7 to be a one. But without knowing what
- you're trying to do, it's impossible to say what it should be.
- However, you definitely need to understand these type of operations if
- you want to be a programmer.
-
- _______________________________________________________
- Marty Fried - mfried@linex.com Press Enter to Exit
- San Anselmo, CA -NT message
- (MSVC4 + MFC) && (Win95 || NT);
-